<template>
  <div>
    <h1>Posts List</h1>
    <ul>
      <li v-for="post in posts" :key="post.slug">{{ post.title }}</li>
    </ul>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex'
export default {
  name: 'PostList',
  metaInfo: {
    title: 'Posts'
  },
  data() {
    return {
    }
  },
  computed: {
    ...mapState(['posts'])
  },
  // Vue SSR 特殊为服务端渲染提供的一个生命周期函数
  serverPrefetch () {
    // 发起 action，返回 Promise
    return this.getPosts()
  },
  methods: {
    ...mapActions(['getPosts'])
  }
  // async created () {
  //   console.log('Posts Created Start')
  //   const { data } = await axios({
  //     method: 'GET',
  //     url: 'https://conduit.productionready.io/api/articles'
  //   })
  //   this.posts = data.articles
  //   console.log('Posts Created End')
  // }
}
</script>

<style>

</style>